#ifndef GRPCSERVER_H
#define GRPCSERVER_H
#include <stdint.h>
#include <string>
#include <thread>
#include <memory>

#include "absl/strings/str_format.h"

#include <grpcpp/ext/proto_server_reflection_plugin.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;

/***************************************************************
*  @Copyright:  Copyright (c) 2024 LK. All rights reserved.
*  @FileName:   grpcserver.h
*  @Brief:      grpc 服务器 封装
*  @Author:     HXJ
*  @Date:       2024-08-17
****************************************************************/

class GrpcServer
{
public:
    static GrpcServer *instance();

    ~GrpcServer();
private:
    GrpcServer();
    GrpcServer(GrpcServer &&) = delete;
    GrpcServer(const GrpcServer &) = delete;
    void operator = (const GrpcServer &) = delete;
public:
    //注册服务
    void RegisterService(std::shared_ptr<grpc::Service> service);

    void StartGrpcServer(std::string ip, uint16_t port);

private:
    void serverWait();

private:
    std::string m_ip;
    uint16_t m_port = 0;
    std::thread m_thread;

    std::unique_ptr<Server> m_server;

    std::list<std::shared_ptr<grpc::Service>> m_listService;
};

extern std::unique_ptr<GrpcServer> g_pGrpcServer;

#endif // GRPCSERVER_H
